<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*"  %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ include file="config.jsp" %>
<%@ page import="elibrary.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
        <link href="../style.css" rel="stylesheet" type="text/css" />


    </head>
    <body>
        <% response.setDateHeader("Expires",-1);%>
        <%

        try{
	
                //Connection is made to the database
	
                        String responseText=new String("");

                        String Username=(String) request.getParameter("qparam");
                        Connection con=DaoConnection.getcon(connectURL, DBuser, DBpass);
                        String query;
                        ResultSet rs=null;
                        PreparedStatement ps=null;
                        query="SELECT * FROM USERS WHERE USERNAME='"+Username+"'";
                        ps=con.prepareStatement(query);
                        rs=ps.executeQuery();
		
                        //checks is put so that the length of the username is between 5 and 25
		
                        if (Username.length()>5 && Username.length()<25)
                        {
                                if(rs.next())
                                {
			
                                        if (rs.getString("username").equals(Username))
                                        {
                                                responseText="<img src="+'"'+"images/cross.gif"+'"'+">";
                                                responseText+="<input type='hidden' name='usercheck' value='0'>";
                                        }
                                }
			
		
                                else
                                {	responseText="<img src="+'"'+"images/check.gif"+'"'+">";
                                        responseText+="<input type='hidden' name='usercheck' value='1'>";
                                }
                        }
                        else{
                                responseText="<img src="+'"'+"images/cross.gif"+'"'+">";
                                //	responseText="<font color='red'>Username unavailable! </font>";
                                        responseText+="<input type='hidden' name='usercheck' value='0'>";
                        }
		
                out.print(responseText);
                con.close();
		 
         }
         catch(Exception e)
                {
                        out.println("Error "+e.getMessage());
		
                }
	
        %>
    </body>
</html>
